import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import tailwindcss from '@tailwindcss/vite'
import ys from 'vite-plugin-compression'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react(), tailwindcss(),
  // gzip压缩
  ys({
    algorithm: 'gzip'
  }), {
    // 将console.log换成console.info
    name: 'my-plugin', transform(code) {
      return code.replace(/console\.log/g, 'console.info')
    }
  }
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  // 移除console
  esbuild: {
    drop: ['console', 'debugger']
  },
  server: {
    proxy: {
      '^/api': {
        target: 'http://blogapi.shbwyz.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    }
  }
})

// gzip压缩
// 将console.log换成console.info
// 移除console